class Solution {
public:
    /*void swap(int& x, int& y) {
        int z = x;
        x = y;
        y = z;
    }
    void Downajust(vector<int>& num, int father, int size) {
        while (father <= size) {
            int child = father * 2 + 1;
            while (child < size) {
                if (num[child] < num[child + 1])
                    child++;
                if (num[father] < num[child]) {
                    swap(num[father], num[child]);
                    father = child;
                    child = father * 2;
                } else
                    break;
            }
        }
    }
    int lastStoneWeight(vector<int>& stones) {
        int size = stones.size();
        for (int i = (size - 2) / 2; i >= 0; i--) {
            SortDown(stones, i, size);
        }
        int end = size - 1;
        while (end) {
            Swap(&ptr[end], &ptr[0]);
            SortDown(ptr, 0, end--);
        }

    }*/
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> q;
        for (auto ch : stones)
            q.push(ch);
        while (q.size() > 1)
        {
            int x = q.top();
            q.pop();
            int y = q.top();
            q.pop();
            if (x != y) q.push(x - y);
        }
        return q.size() > 0 ? q.top() : 0;
    }
};
class KthLargest {
public:
    priority_queue<int, vector<int>, greater<int>> q;
    int size;
    KthLargest(int k, vector<int>& nums) {
        size = k;
        for (auto ch : nums)
        {
            q.push(ch);
            if (q.size() > size) q.pop();
        }
    }

    int add(int val) {
        q.push(val);
        if (q.size() > size) q.pop();
        return q.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */
class Solution {
public:
    typedef pair<string, int> value;
    struct cmp
    {
        bool operator()(const value& x, const value& y)
        {
            if (x.second == y.second)
            {
                return x.first < y.first;
            }
            return x.second > y.second;
        }
    };
    